#include "store_app.h"

int main(int argc, const char *argv[])
{

	ledfd = open(LEDPATH, O_RDWR);
	if (ledfd < 0)
	{
		perror("open error");
		return -1;
	}

	int ret = sys_init();
	if (-1 == ret)
	{
		puts("sys init error");
		return -1;
	}
	puts("sys init OK");

	while (1)
	{
		sleep(1);
		if (env_tmp > set_tmp_up)
		{
			puts("cooling device open");

			env_tmp -= 1;
			env_fan = 1;
		}
		else if (env_tmp < set_hum_dow)
		{
			puts("heat device open");

			env_fan = 0;
			env_tmp += 1;
		}

		if (env_illu > set_illu_up)
		{
			puts("illu device open");

			env_illu -= 1;
			env_led = 1;
		}
		else if (env_illu < set_illu_dow)
		{
			puts("illu device close");

			env_illu += 1;
			env_led = 0;
		}

		if (env_hum > set_hum_up)
		{
			puts("dehum device open");

			env_hum -= 1;
			env_beep = 1;
		}
		else if (env_hum < set_hum_dow)
		{
			puts("dehum device close");

			env_hum += 1;
			env_beep = 0;
		}
	}
	return 0;
}
